import axios from "axios";
import type {AxiosRequestHeaders, AxiosResponse } from 'axios';
import NProgress from "nprogress";
NProgress.configure({showSpinner:false});

interface ResponseData<T> {
    code: number;
    data: T;
}

const request = axios.create({
  baseURL: "/wangyi",
  timeout: 50000,
});

// 添加请求拦截器
request.interceptors.request.use((config) => {
  NProgress.start();
  return config;
});

// 添加响应拦截器
request.interceptors.response.use(
  async (response: AxiosResponse<ResponseData<any>, any>) => {
    NProgress.done();
    return response.data.data
    
  },
  (error) => {
    NProgress.done();
    return Promise.reject(error);
  }
);

export default request;